import { Tile } from './Tile.js';

export class Board {
  constructor(rows = 5, cols = 9) {
    this.rows = rows; this.cols = cols;
    this.tiles = Array.from({ length: rows }, () => Array.from({ length: cols }, () => new Tile('grass')));
  }
  canPlace(row, col, plant) {
    const t = this.tiles[row][col];
    return !t.plant && (!plant || plant.allowedTileTypes?.includes(t.type));
  }
  place(row, col, plant) {
    if (!this.canPlace(row, col, plant)) return false;
    this.tiles[row][col].plant = plant;
    plant.gridPos = { row, col };
    return true;
  }
}